<style>
    .panel-header, .panel-body {
        border-width: 0px;
    }

    .datagrid, .combo-p {
        border: solid 1px #D4D4D4;
    }

    .panel-title {
        cursor: pointer;
    }

    .inlineblock {
        margin-top: 10px;
    }

    .inlineblock div {
        display: inline-block;
    }

    .inlineblock div label {
        display: inline-block;
        top: 5px;
    }

    .newform {
        width: 70%;
    }

    .editform {
        width: 70%;
    }



    .searchClass label {        width: 5%;
        font-weight: bold;
    }
    .searchClass input{
        margin-right:60px;
    }
    #Search {
        float: right;
        margin-right: 4%;
        width: 40%;
    }
    #Reset {
        float: right;
        margin-right: 2%;
        width: 40%;
    }
    .col-md-1{
        text-align: right;
        display: inline-block;
    }
    .rowstyle{
        margin-top: 1%;
    }
</style>
<div class="row">
    <div id="breadcrumb" class="col-xs-12">
        <a href="#" class="show-sidebar">
            <i class="fa fa-bars"></i>
        </a>
        <ol class="breadcrumb pull-left">
            <li><a href="#">全球房产</a></li>
            <li><a href="#">房产管理</a></li>
        </ol>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <div class="box-name">
                    <i class="fa "></i>
                    <span>房产管理</span>
                </div>
                <div class="box-icons">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                    <a class="expand-link">
                        <i class="fa fa-expand"></i>
                    </a>
                    <a class="close-link">
                        <i class="fa fa-times"></i>
                    </a>
                </div>
                <div class="no-move"></div>
            </div>

            <div class="box-content table-responsive" style="padding-top: 15px;">
                <!--功能面板 S-->
                <div class="panel panel-default" style="border: 1px solid #CCC;">
                    <div class="panel-heading" role="tab" id="headingOne">
                        <h4 class="panel-title" data-toggle="collapse" data-target="#collapseForAdd">
                            功能面板 <span class="fa fa-chevron-down" style="float: right"></span>
                        </h4>
                    </div>

                    <div id="collapseForAdd" class="panel-collapse collapse in" role="tabpanel"
                         aria-labelledby="headingOne">
                        <div class="panel-body">
                            <div class="container-fluid" style="margin-top: 10px;">
                                <!--操作-->
                                <div id="operationpanel" class="col-xs-12" style="overflow: hidden;">
                                    <div class="col-xs-12 btn-menu-top-minus" style="margin-top:0;">
                                        <button class="btn btn-primary btn-sm addImg">
                                            <i class="fa fa-file-o"></i> 添加
                                        </button>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
                <!--功能面板 E-->
                <!--主信息面板 S-->
                <div class="panel panel-default" style="border: 1px solid #CCC;">
                    <div class="panel-heading" role="tab" id="headingTwo">
                        <h4 class="panel-title" data-toggle="collapse" data-target="#collapseForStudentTable">
                            轮播图统计<span class="fa fa-chevron-down" style="float: right"></span>
                        </h4>
                    </div>
                    <div id="collapseForStudentTable" class="panel-collapse collapse in" role="tabpanel"
                         aria-labelledby="headingTwo">
                        <!--搜索框-->
                        <div class="panel-body" style="overflow: hidden;">

                            <div class="searchClass">
                                <div class="row rowstyle">
                                    <div class="col-md-1"><b>关键字</b></div>
                                    <div class='col-md-2'>
                                        <input  class="SearchForm form-control" type="text" name="key" style="width:140px;font-size: 13px;" placeholder="地区名称" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        <br/>
                        <button id="Search" class="btn btn-primary btn-sm" style="width:150px;">
                            <i class="fa fa-search"></i> 查询
                        </button><button id="Reset" class="btn btn-primary btn-sm" style="width:120px;">
                        <i class="fa fa-search"></i> 清空查询条件
                    </button>


                    </div>

                </div>
                <!--信息表 S-->
                <table id="datatable_info" data-size="15" style="width: 100%">
                </table>
                <!--信息表 E-->
            </div>
        </div>
        <!--主信息面板 E-->
    </div>
</div>
<script src="static/js/ajax/house.js"></script>
<script>
    $('#createtime').datepicker({
        language: 'zh-CN',
        format: "yyyy-mm-dd",
        todayBtn: "linked",
        autoclose: true,
        todayHighlight: true,
        clearBtn: true,
    });

    /**
     * 删除
     */
    function deleteInfo(obj){
        var cid = obj.name;
        $.TeachDialog({
            content: "确认删除此记录？",
            showCloseButton: true,
            showCloseButtonName: '取消',
            otherButtons: ['确认'],
            otherButtonStyles: ['btn-danger'],
            clickButton: function(sender, modal, index) {
                modal.modal('hide');
                $.ajax({
                    url: 'admin/House/delHouse', //form action
                    dataType: 'JSON', //返回体类型
                    type: 'POST', // form type
                    data: "id=" + cid,
                    success: function(data) {
                        if (data.code == 200) {
                            layer.msg(data.msg,{icon:6,time:2000});
                            $('#datatable_info').datagrid('reload');
                        } else {
                            layer.msg(data.msg,{icon:5,time:2000});
                        }
                    },
                    error: function() {
                        layer.msg("删除失败!",{icon:5,time:2000});
                    }
                });
            }
        })
    }

    function updateInfo(obj){
        var cid = obj.name;
        $.ajax({
            url: 'admin/House/updateHouse',
            data: "id=" + cid,
            type: 'POST',
            dataType: 'HTML',//返回的数据类型
            success: function (updatemodalhtml) {
                content = updatemodalhtml;
                //弹出修改框
                $.TeachDialog({
                    title: '修改房产',
                    content: content,
                    showCloseButton: true,
                    showCloseButtonName: '关闭',
                    otherButtons: ['保存'],
                    largeSize:true,
                    otherButtonStyles: ['btn-primary'],
                    clickButton: function (sender, modal, index) {
                        var formData = new FormData($( "#addForm" )[0]);
                        if($('#house_name').val() == ''){
                            layer.msg('房产名称不能为空',{icon:5,time:2000});
                            return;
                        }
                        if($('#introduce').val() == ''){
                            layer.msg('简介不能为空',{icon:5,time:2000});
                            return;
                        }
                        if($('#areas').val() == '' && $("input[type='checkbox']").is(':checked')==false){
                            layer.msg('房产类型和房产面积不能同时为空',{icon:5,time:2000});
                            return;
                        }
                        if($('#price').val() == ''){
                            layer.msg('房产价格不能为空',{icon:5,time:2000});
                            return;
                        }
                        if($('#place').val() == ''){
                            layer.msg('地区不能为空',{icon:5,time:2000});
                            return;
                        }
                        $.ajax({
                            url: 'admin/House/update',
                            data: formData,
                            async: false,//1，这四个要写上，否则点击没反应
                            cache: false,//2
                            contentType: false,//3
                            processData: false,//4
                            type: 'POST',
                            dataType: 'JSON',

                            success: function(returnData) {
                                if (returnData.code == 100) {
                                    layer.msg(returnData.msg,{icon:5,time:2000});
                                } else {
                                    modal.modal('hide');
                                    layer.msg(returnData.msg,{icon:6,time:2000});
                                    $('#datatable_info').datagrid('reload');
                                }
                            },
                            error: function() {
                                layer.msg("修改失败！",{icon:5,time:2000});
                            },
                        });
                    },
                });
            },
            error: function () {
                $.TeachDialog({
                    content: '系统异常，请联系管理员'
                });
                return;
            }
        });
    }
</script>
